<?php
namespace app\madmin\controller;
use app\madmin\model\SystemLogModel;
use app\madmin\model\SystemMemberModel;

/**
 * 权限控制器
 * @author  黄明杰 vx:HMJ125855
 * @version 20190101
 */
class SystemCount extends PublicBase{

	# 日志统计方法
    public function showLog(){
        $SystemLog = new SystemLogModel;
        $SystemMember = new SystemMemberModel;

        $Where = $this->getFormWhere();

        if(!empty($Where['log_create'])){
            $Types = 2;
            $Dates = $this->makeDateTime($Where['log_create'][1][0], $Where['log_create'][1][1], $Types);
            $Group = 'month,day';
        }else{
            $Date = input('param.date_type');
            if(!empty($Date)){
                $Backs = $this->makeDateType($Date);
            }else{
                $Backs = $this->makeDateType(3);
            }

            $Where['log_create'] = $Backs['where'];
            $Types = $Backs['types'];
            $Dates = $Backs['dates'];
            $Group = $Backs['group'];
        }

        $Field['Count(1)'] = 'num0';
        $Field['COUNT(IF(log_type = 1,true,null))'] = 'num1';
        $Field['COUNT(IF(log_type = 2,true,null))'] = 'num2';
        $Field['COUNT(IF(log_type = 3,true,null))'] = 'num3';
        $Field['COUNT(IF(log_type = 4,true,null))'] = 'num4';
        $Field['COUNT(IF(log_type = 5,true,null))'] = 'num5';
        $Field['COUNT(IF(log_type = 6,true,null))'] = 'num6';
        $Field['COUNT(IF(log_state = 1,true,null))'] = 'num7';
        $Field['COUNT(IF(log_state = 2,true,null))'] = 'num8';

        $Count = $SystemLog->mInfo($Where, $Field);

        $Field['FROM_UNIXTIME(log_create, "%Y")'] = 'year';
        $Field['FROM_UNIXTIME(log_create, "%m")'] = 'month';
        $Field['FROM_UNIXTIME(log_create, "%d")'] = 'day';

        $Order = 'year,month,day';

        $Lists = $SystemLog->mCensus($Where, $Field, $Group, $Order);
        $Lists = $this->makeDateList($Lists, $Dates, $Types, 9);

        $Where = [];
        $Where['member_state'] = 1;

        $Admin = $this->checkLogin();

        if($Admin['AdminID'] != 1){
            $Where['member_id'] = ['NEQ', 1];
        }

        return $this->fetch('SystemCount/showLog', [
            'Lists' => $Lists,
            'Count' => $Count,
            'Admin' => $SystemMember->mAll($Where, 'member_id,member_user'),
            'Dates' => $this->getLexiconCache('DATE_TIME')
        ]);
    }

}